package lab02.Test24;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;

public class Test24 {
    public static void main(String[] args) throws ParseException {

        Scanner sc=new Scanner(System.in);
        System.out.println("输入第一个“yyyyMMdd”日期：");
        String n=sc.nextLine();


        SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyyMMdd");
        Date date=simpleDateFormat.parse(n);
        String a=String.format("%tY年%tm月%td日",date,date,date);
        System.out.println(a);

        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        long time1=cal.getTimeInMillis();


        System.out.println("输入第二个“yyyyMMdd”日期：");
        String m=sc.nextLine();

        SimpleDateFormat simpleDateFormat1=new SimpleDateFormat("yyyyMMdd");
        Date date1=simpleDateFormat.parse(m);
        String d=String.format("%tY年%tm月%td日",date1,date1,date1);

        cal.setTime(date1);
        long time2=cal.getTimeInMillis();
        System.out.println(d);

        long between_days=(time2-time1)/(1000*3600*24);

        System.out.println("两个日期相差:"+Math.abs(between_days)+"天");
    }

}
